-
Notifications
You must be signed in to change notification settings - Fork 619
chore!: update to JS SDK 2.x #2738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- instr-bunyan and examples/bunyan
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2738 +/- ##
==========================================
- Coverage 91.86% 91.73% -0.14%
==========================================
Files 171 166 -5
Lines 8172 8103 -69
Branches 1660 1546 -114
==========================================
- Hits 7507 7433 -74
- Misses 665 670 +5
🚀 New features to boost your workflow:
|
drop CI unit-testing of versions below 18.19.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewer note: The updates to this file are just from the linter doing style changes. Normally .js files in the repo are not processed by npm run lint.
|
Thanks for working on this! As discussed offline, let's update this or do a follow-up PR with some basic upgrade/migration notes for the resource detector change. |
The package-lock update also includes an update of grcp-js (1.12.6 -> 1.13.0) https://github.com/grpc/grpc-node/releases/tag/%40grpc%2Fgrpc-js%401.13.0
Added here: open-telemetry/opentelemetry-js#5535 |
detectors/node/opentelemetry-resource-detector-container/src/detectors/ContainerDetector.ts
Show resolved
Hide resolved
detectors/node/opentelemetry-resource-detector-gcp/src/detectors/GcpDetector.ts
Show resolved
Hide resolved
detectors/node/opentelemetry-resource-detector-github/src/detectors/GitHubDetector.ts
Show resolved
Hide resolved
plugins/web/opentelemetry-instrumentation-document-load/test/documentLoad.test.ts
Outdated
Show resolved
Hide resolved
This shows there are some more test failures in instr-document-load to deal with.
…ing.secureConnectionStart changed in sdk-trace-web
pichlermarc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for working on this. 🙌
I pinged two component owners for their input on not exporting the detector classes anymore. In general I agree with that change and it also aligns them with the other detector packages. I think there's no benefit to having the classes exported. For the AWS detectors, which are stable, this is likely a good time to do this as dropping support for old Node.js versions means this will bump it to 2.0 anyway.
| AwsBeanstalkDetectorSync, | ||
| awsBeanstalkDetectorSync, | ||
| } from './AwsBeanstalkDetectorSync'; | ||
| export { awsBeanstalkDetector } from './AwsBeanstalkDetector'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I agree with dropping class exports where they're not needed, I'm wondering: was this dropped intentionally?
cc @jj22ee: what's your preference - should the class export be kept? An end-user will likely just use the constant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was intentional, yes, for the reasons you gave above:
- The detector instance, e.g.
awsBeanstalkDetector, is the thing users will want to use. - There is some precedent from the core repo's detector classes also having been dropped in the 2.0.0 release or earlier.
- I don't know of a use case for exporting the class.
- We have a breaking change version bump already for dropping Node 14 and 16 support, so it was an opportunity for this breaking change.
However, I don't feel strongly, so I'm okay to re-add exporting these if others feel we should.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clarifying :)
I agree that we should drop class exports. It's also easy to add back later in a feature release if needed 👍
detectors/node/opentelemetry-resource-detector-container/src/detectors/ContainerDetector.ts
Outdated
Show resolved
Hide resolved
| * limitations under the License. | ||
| */ | ||
| export * from './ContainerDetector'; | ||
| export { containerDetector } from './ContainerDetector'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, the class used to be exported, but the end-user never really needs to be a class. I'm fine with this change.
cc @abhee11 (component owner)
| } = await this._fetchIdentity(); | ||
| const hostname = await this._fetchHost(); | ||
| _getAttributes(): DetectedResourceAttributes { | ||
| const dataP = Promise.all([this._fetchIdentity(), this._fetchHost()]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
running some tests in Elastic's distribution I got an error of an unhandled promise rejection
node ./test/agent-metadata.test.js
TAP version 13
# agent metadata
# agent metadata default case
not ok 1 exited successfully: err=Error: Command failed: /Users/david/.nvm/versions/node/v18.19.0/bin/node ./fixtures/use-http-get.js node:internal/process/promises:288 triggerUncaughtException(err, true /* fromPromise */); ^ Error: ECS metadata api request timed out. at Timeout._onTimeout (/Users/david/Documents/repos/otel/opentelemetry-js-contrib/detectors/node/opentelemetry-resource-detector-alibaba-cloud/build/src/detectors/AlibabaCloudEcsDetector.js:91:29) at listOnTimeout (node:internal/timers:569:17) at process.processTimers (node:internal/timers:512:7) Node.js v18.19.0
---
operator: error
at: done (/Users/david/Documents/repos/el/elastic-otel-node/packages/opentelemetry-node/test/testutils.js:648:35)
stack: |-
Error: Command failed: /Users/david/.nvm/versions/node/v18.19.0/bin/node ./fixtures/use-http-get.js
node:internal/process/promises:288
triggerUncaughtException(err, true /* fromPromise */);
^
Error: ECS metadata api request timed out.
at Timeout._onTimeout (/Users/david/Documents/repos/otel/opentelemetry-js-contrib/detectors/node/opentelemetry-resource-detector-alibaba-cloud/build/src/detectors/AlibabaCloudEcsDetector.js:91:29)
at listOnTimeout (node:internal/timers:569:17)
at process.processTimers (node:internal/timers:512:7)
Node.js v18.19.0
at ChildProcess.exithandler (node:child_process:422:12)
at ChildProcess.emit (node:events:517:28)
at maybeClose (node:internal/child_process:1098:16)
at ChildProcess._handle.onexit (node:internal/child_process:303:5)
...
# stdout:
# |{"name":"elastic-otel-node","level":30,"preamble":true,"distroVersion":"0.7.0","env":{"os":"darwin 24.3.0","arch":"arm64","runtime":"Node.js v18.19.0"},"msg":"start Elastic Distribution of OpenTelemetry Node.js","time":"2025-03-17T12:12:47.063Z"}
# |{"name":"elastic-otel-node","level":50,"msg":"Accessing resource attributes before async attributes settled","time":"2025-03-17T12:12:47.074Z"}
# |{"name":"elastic-otel-node","level":50,"msg":"Accessing resource attributes before async attributes settled","time":"2025-03-17T12:12:47.074Z"}
# |{"name":"elastic-otel-node","level":50,"msg":"Accessing resource attributes before async attributes settled","time":"2025-03-17T12:12:47.074Z"}
# |{"name":"elastic-otel-node","level":50,"msg":"Accessing resource attributes before async attributes settled","time":"2025-03-17T12:12:47.074Z"}
# |{"name":"elastic-otel-node","level":50,"msg":"Accessing resource attributes before async attributes settled","time":"2025-03-17T12:12:47.074Z"}
# |client response: 200 {
# | date: 'Mon, 17 Mar 2025 12:12:47 GMT',
# | expires: '-1',
# | 'cache-control': 'private, max-age=0',
# | 'content-type': 'text/html; charset=ISO-8859-1',
# | 'content-security-policy-report-only': "object-src 'none';base-uri 'self';script-src 'nonce-8TGjP3Y6JPSYBgb6x6Gcsg' 'strict-dynamic' 'report-sample' 'unsafe-eval' 'unsafe-inline' https: http:;report-uri https://csp.withgoogle.com/csp/gws/other-hp",
# | server: 'gws',
# | 'x-xss-protection': '0',
# | 'x-frame-options': 'SAMEORIGIN',
# | 'set-cookie': [Array],
# | 'accept-ranges': 'none',
# | vary: 'Accept-Encoding',
# | connection: 'close',
# | 'transfer-encoding': 'chunked'
# |}
# |client response: end
# stderr:
# |node:internal/process/promises:288
# | triggerUncaughtException(err, true /* fromPromise */);
# | ^
# |
# |Error: ECS metadata api request timed out.
# | at Timeout._onTimeout (/Users/david/Documents/repos/otel/opentelemetry-js-contrib/detectors/node/opentelemetry-resource-detector-alibaba-cloud/build/src/detectors/AlibabaCloudEcsDetector.js:91:29)
# | at listOnTimeout (node:internal/timers:569:17)
# | at process.processTimers (node:internal/timers:512:7)
# |
# |Node.js v18.19.0
# skip checkTelemetry because process errored out
1..1
# tests 1
# pass 0
# fail 1In this detector and other that are doing async operations we have promises that need to be handled if they reject. I think is because now the detectResources method from @opentelemetry/resources does defer the handling of the rejected ones. Checking ResourceImpl constructor we see values are kept but not handled until waitForAsyncAttributes is called (I think in exporters).
We could solve it by being more eager on handling the async attributes in ResourceImpl or by handling all possible rejections in each detector. Doing the later means we should add a second callback function for each promised value in the attribs object. Something like
const resolveUndef = () => undefined;
return {
[SEMRESATTRS_CLOUD_PROVIDER]: dataP.then(
() => CLOUDPROVIDERVALUES_ALIBABA_CLOUD,
resolveUndef
),
[SEMRESATTRS_CLOUD_PLATFORM]: dataP.then(
() => CLOUDPLATFORMVALUES_ALIBABA_CLOUD_ECS,
resolveUndef
),
// Data from _fetchIdentity()
[SEMRESATTRS_CLOUD_ACCOUNT_ID]: dataP.then(
data => data[0]['owner-account-id'],
resolveUndef
),
[SEMRESATTRS_CLOUD_REGION]: dataP.then(data => data[0]['region-id']),
[SEMRESATTRS_CLOUD_AVAILABILITY_ZONE]: dataP.then(
data => data[0]['zone-id']
),
[SEMRESATTRS_HOST_ID]: dataP.then(
data => data[0]['instance-id'],
resolveUndef
),
[SEMRESATTRS_HOST_TYPE]: dataP.then(
data => data[0]['instance-type'],
resolveUndef
),
// Data from _fetchHost()
[SEMRESATTRS_HOST_NAME]: dataP.then(
data => data[1],
resolveUndef
),
};There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@david-luna Thanks! I'll have to update most of the res detectors in this PR for this.
Some notes:
- I think there is effectively a regression in
@opentelemetry/[email protected]here. It doesn't adequately guard against a rejection in async resource attribute values anymore. I'll raise an issue (and perhaps PR) for this. - In the meantime, for a Resource Detector to use
@opentelemetry/[email protected], the burden is now on the Resource Detector author to never have its async attribute promises reject. - I'm really curious why tests didn't catch this: some or all of tests for
@opentelemetry/resources,@opentelemetry/resource-detector-*, and@opentelemetry/auto-instrumentations-nodeshould catch this. My total guess is that there are no out-of-process tests for these, and that mocha has someuncaughtExceptionorunhandledRejectionprocess event handler that accidentally traps these. - I think the section in the migration guide (https://github.com/open-telemetry/opentelemetry-js/blob/main/doc/upgrade-to-2.x.md#-opentelemetryresources-changes-for-implementors-of-resource-detectors) should be updated to cope with this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I'm really curious why tests didn't catch this: some or all of tests for
@opentelemetry/resources,@opentelemetry/resource-detector-*, and@opentelemetry/auto-instrumentations-nodeshould catch this.
@opentelemetry/resource-detector-*: At least for@opentelemetry/resource-detector-alibaba-cloudall the tests usingdetectResourceswould immediately (in the same tick) callresource?.waitForAsyncResources(), which results in the asynctry/catchin that method guarding against promise rejections in the async attrs.
I have a coming test case that adds this before the resource?.waitForAsyncResources():
import { setTimeout as setTimeoutP } from 'timers/promises';
// This pause simulates the delay between `detectResources` and
// `waitForAsyncAttributes` typically called later in an exporter.
await setTimeoutP(200); // Hope this is enough time to get error response.This triggers the error.
@opentelemetry/auto-instrumentations-node: Itsregister.test.tsdoes do an out of process test. However, it setsOTEL_NODE_RESOURCE_DETECTORS: 'none',hence no testing of async resource detection. With the following diff, the test fails:
--- a/metapackages/auto-instrumentations-node/test/register.test.ts
+++ b/metapackages/auto-instrumentations-node/test/register.test.ts
@@ -33,7 +33,6 @@ function runWithRegister(path: string): PromiseWithChild<{
timeout: 1500,
killSignal: 'SIGKILL', // SIGTERM is not sufficient to terminate some hangs
env: Object.assign({}, process.env, {
- OTEL_NODE_RESOURCE_DETECTORS: 'none',
OTEL_TRACES_EXPORTER: 'console',
OTEL_LOG_LEVEL: 'debug',There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I think there is effectively a regression in
@opentelemetry/[email protected]here. It doesn't adequately guard against a rejection in async resource attribute values anymore. I'll raise an issue (and perhaps PR) for this.
I've opened open-telemetry/opentelemetry-js#5539 for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be fixed in commit e3a689f
…eject Also tweak the auto-instrumentations-node/register.js test to actually use resource detectors, to help test if there are issues with them. Refs: open-telemetry/opentelemetry-js#5539
…g now that target is es2022 As of open-telemetry#2738 the tsconfig target is es2022 now, so this special case is no longer necessary.
Co-authored-by: Marc Pichler <[email protected]>
@opentelemetry/*packages from opentelemetry-js.gitper https://github.com/open-telemetry/opentelemetry-js/blob/main/doc/upgrade-to-2.x.md
^18.19.0 || >=20.6.0. This means that support for Node.js 14 and 16 has been dropped.ContainerDetectorclass is no longer exportedawsBeanstalkDetectorSync-> useawsBeanstalkDetectorawsEc2DetectorSync-> useawsEc2DetectorawsEcsDetectorSync-> useawsEcsDetectorawsEksDetectorSync-> useawsEksDetectorawsLambdaDetectorSync-> useawsLambdaDetectorAwsBeanstalkDetector,AwsEcsDetector,AwsEksDetector,AwsLambdaDetector,note to revewiers
This is ready for review. The remaining failing test will be fixed when there is a new release of 2.x/0.200.x from the core repo with open-telemetry/opentelemetry-js#5524 (see the checklist below).
checklist
instrumentation-document-loadtests passing2.0.0/0.200.0release once that is out